export default class JJDateUtil {

    // 数据格式化
    static formatNumber(n) {
        n = n.toString()
        return n[1] ? n : '0' + n
    }

    /**
    * 将当前时间转化为年 月 日 时 分 秒
    * format：返回格式--20180713092518
    */
    static formatCurrentTimeWithUnunit() {
        let returnArr = [];
        let date = new Date();
        returnArr.push(date.getFullYear());
        returnArr.push(JJDateUtil.formatNumber(date.getMonth() + 1));
        returnArr.push(JJDateUtil.formatNumber(date.getDate()));
        returnArr.push(JJDateUtil.formatNumber(date.getHours()));
        returnArr.push(JJDateUtil.formatNumber(date.getMinutes()));
        returnArr.push(JJDateUtil.formatNumber(date.getSeconds()));
        let format = returnArr.join('');
        return format;
    }

    // 将时间20180713092518转化为时间戳
    static dateFromString(dateString) {
        let year = parseInt(dateString.substring(0, 4));
        let month = parseInt(dateString.substring(4, 6)) - 1;
        let day = parseInt(dateString.substring(6, 8));
        let hour = parseInt(dateString.substring(8, 10));
        let min = parseInt(dateString.substring(10, 12));
        let sec = parseInt(dateString.substring(12, 14));
        return new Date(year, month, day, hour, min, sec);
    }
}
